package cn.tedu.luban.account.main.rpc;

import cn.tedu.luban.account.api.AccountApi;
import cn.tedu.luban.account.main.service.AccountService;
import cn.tedu.luban.account.protocol.dto.AccountDTO;
import cn.tedu.luban.account.protocol.param.AccountCreateParam;
import cn.tedu.luban.account.protocol.param.AccountPayParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class AccountApiImpl implements AccountApi {

    @Autowired
    private AccountService accountService;

    /**
     * 创建账户数据 返回1-成功创建 返回0-未创建
     */
    @Override
    public Long createAccount(AccountCreateParam accountCreateParam) {
        Long result = 0L;
        try{
            result = accountService.createAccount(accountCreateParam);
        }catch (Throwable e){
            log.error("新建账号失败,账号参数:{}",accountCreateParam);
        }

        return result;
    }

    @Override
    public AccountDTO getAccount(Long userId) {
        AccountDTO accountDTO = null;
        try{
            accountDTO = accountService.getAccount(userId);
        }catch (Throwable e){
            log.error("获取账号信息失败,用户id:{}",userId);
        }
        return accountDTO;
    }

    @Override
    public Long mockPayment(AccountPayParam param) {

        Long result = 0L;

        try{
            result = accountService.mockPay(param);
        }catch (Throwable e){
            log.error("模拟打款失败,入参:{},异常{}",param,e);
        }

        return result;
    }
}
